﻿CREATE TABLE [dbo].[Routine] (
    [Id]                            INT           IDENTITY (1, 1) NOT NULL,
    [Name]                          VARCHAR (100) NOT NULL,
    [LibraryVersionId]              INT           NOT NULL,
    [ResponsibleId]                 INT           NOT NULL,
    [CategoryId]                    INT           NOT NULL,
    [Class]                         VARCHAR (500) NOT NULL,
    [PredecessorRoutineId]          INT           NULL,
    [PreferredMachineId]            INT           NULL,
    [UseLastVersion]                BIT           DEFAULT ((1)) NOT NULL,
    [Active]                        BIT           DEFAULT ((1)) NOT NULL,
    [ScheduleFinished]              BIT           DEFAULT ((0)) NOT NULL,
    [EstimatedTime]                 INT           NOT NULL,
    [PercentageAcceptableVariation] INT           NOT NULL,
    PRIMARY KEY CLUSTERED ([Id] ASC) WITH (ALLOW_PAGE_LOCKS = ON, ALLOW_ROW_LOCKS = ON, PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF),
    FOREIGN KEY ([CategoryId]) REFERENCES [dbo].[Category] ([Id]) ON DELETE NO ACTION ON UPDATE NO ACTION,
    FOREIGN KEY ([LibraryVersionId]) REFERENCES [dbo].[LibraryVersion] ([Id]) ON DELETE NO ACTION ON UPDATE NO ACTION,
    FOREIGN KEY ([PredecessorRoutineId]) REFERENCES [dbo].[Routine] ([Id]) ON DELETE NO ACTION ON UPDATE NO ACTION,
    FOREIGN KEY ([PreferredMachineId]) REFERENCES [dbo].[Machine] ([Id]) ON DELETE NO ACTION ON UPDATE NO ACTION,
    FOREIGN KEY ([ResponsibleId]) REFERENCES [dbo].[User] ([Id]) ON DELETE NO ACTION ON UPDATE NO ACTION
);

